package com.gxa.controller.parking;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.entity.parking.VehicleSelect;
import com.gxa.service.parking.VehicleListService;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.gxa.entity.parking.VehicleList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-11 10:05:39
 */





@Api(tags = "车辆管理接口")
@RestController
@RequestMapping("/vehicle-list")
public class VehicleListController {
    @Autowired
    private VehicleListService vehicleListService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("分页查询所有车辆")
    @PostMapping("/vehicleList")
    @ResponseBody
    public Result getVehicle(@RequestBody VehicleSelect vehicleSelect){
        PageHelper.startPage(vehicleSelect.getPageNum(),vehicleSelect.getPageSize());
        List<VehicleList> vehicleLists = this.vehicleListService.selectAll();
        PageInfo<VehicleList> vehicLelist = new PageInfo<>(vehicleLists);
        return Result.success(vehicLelist);
    }



    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("多条件查询车辆")
    @PostMapping("/selectByCondition")
    @ResponseBody
    public Result selectByCondition(@RequestBody VehicleSelect vehicleSelect){
        PageHelper.startPage(vehicleSelect.getPageNum(),vehicleSelect.getPageSize());
        List<VehicleList> vs = this.vehicleListService.selectCondition(vehicleSelect);
        PageInfo<VehicleList> ve = new PageInfo<>(vs);
        return Result.success(ve);
    }


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("查询详情")
    @PostMapping("/selectById/{id}")
    @ResponseBody
    public VehicleList selectById(@PathVariable("id") Integer id){
        VehicleList vehicleList = this.vehicleListService.selectById(id);
        return vehicleList;
    }
}

